import java.util.Scanner;


public class Main {
	
	public static void main(String[] args) {
		FileSystem fs = new FileSystem();
		
		Scanner scan = new Scanner(System.in);
		while (scan.hasNextLine()) {
			String input = scan.nextLine().trim();
			String[] splitedInput = input.split(" ");
			String command = splitedInput[0];
			
			if (command.equalsIgnoreCase("CR")) {
				if(splitedInput.length < 2)
					System.out.println("error");
				String fileName = splitedInput[1];
				if(fileName.length() < 4)
					System.out.println(fs.createFile(fileName));
				else System.out.println("error");
				
			} else if (command.equalsIgnoreCase("DE")) {
				if (splitedInput.length < 2)
					System.out.println("error");
				String fileName = splitedInput[1];
				if (fileName.length() < 4)
					System.out.println(fs.deleteFile(fileName));
				else
					System.out.println("error");
				
			} else if (command.equalsIgnoreCase("OP")) {
				if (splitedInput.length < 2)
					System.out.println("error");
				String fileName = splitedInput[1];
				int openPlace = fs.openFile(fileName);
				if (fileName.length() < 4 && openPlace != -1)
					System.out.println(openPlace);
				else
					System.out.println("error");
				
			} else if (command.equalsIgnoreCase("CL")) {
				if (splitedInput.length == 2) {
					int index = Integer.parseInt(splitedInput[1]);
					String feedback = fs.closeFile(index);
					if (!feedback.equalsIgnoreCase("error")) {
						System.out.println(feedback + "closed");
					} else {
						System.out.println("error");
					}
				} else {
					System.out.println("error");
				}
				
			} else if (command.equalsIgnoreCase("WR")) {
				if (splitedInput.length < 3)
					System.out.println("error");
				int index = Integer.parseInt(splitedInput[1]);
				char data = splitedInput[2].charAt(0);
				int count = Integer.parseInt(splitedInput[3]);
				System.out.println(fs.writeToFile(index, data, count));
			
			} else if (command.equalsIgnoreCase("SK")) {
				if(input.length() < 3)
					System.out.println("error");
				int index = Integer.parseInt(splitedInput[1]);
				int pos = Integer.parseInt(splitedInput[2]);
				System.out.println(fs.seek(index, pos));
				
			} else if (command.equalsIgnoreCase("DR")) {
				System.out.println(fs.directory());
				
			} else if (command.equalsIgnoreCase("IN")) {
				if (splitedInput.length == 1) {
					System.out.println(fs.init(null));
				} else if (splitedInput.length == 2) {
					System.out.println(fs.init(splitedInput[1]));
				} else {
					System.out.println("error");
				}
			
			} else if (command.equalsIgnoreCase("SV")) {
				if (input.length() < 2)
					System.out.println("error");
				System.out.println(fs.save(splitedInput[1]));
			
			} else if (command.equalsIgnoreCase("RD")) {
				if(input.length() < 3)
					System.out.println("error");
				int index = Integer.parseInt(splitedInput[1]);
				int count = Integer.parseInt(splitedInput[2]);
				System.out.println(fs.readFile(index, count));
			} else {

			}
		}
		scan.close();
	}

}
